<!DOCTYPE html>
<html lang="zh-cn">
   <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>{$CONF['mallTitle']}后台管理中心</title>
      <link href="__PUBLIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <link href="__ROOT__/Apps/Admin/View/css/AdminLTE.css" rel="stylesheet" type="text/css" />
      <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.min.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
      <![endif]-->
      <script src="__PUBLIC__/js/jquery.min.js"></script>
      <script src="__PUBLIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
      <script src="__PUBLIC__/js/common.js"></script>
      <script src="__PUBLIC__/plugins/plugins/plugins.js"></script>
   </head>
   <script>
   function editName(obj){
	   Plugins.waitTips({title:'信息提示',content:'正在操作，请稍后...'});
	   $.post("{:U('Admin/WxUsers/editName')}",{id:$(obj).attr('dataId'),userRemark:obj.value},function(data,textStatus){
			var json = WST.toJson(data);
			if(json.status=='1'){
				Plugins.setWaitTipsMsg({content:'操作成功',timeout:1000,callback:function(){
				}});
			}else{
				Plugins.closeWindow();
				Plugins.Tips({title:'信息提示',icon:'error',content:'操作失败!',timeout:1000});
			}
		});
   }
   var userTotal,num=0;
   function wxSynchro(){
	   Plugins.confirm({title:'信息提示',content:'您确定与微信用户管理同步吗?</br>(用户越多同步时间将越久)',okText:'确定',cancelText:'取消',okFun:function(){
		   Plugins.closeWindow();
		   Plugins.waitTips({title:'信息提示',content:'正在操作，请稍后...'});
		   $.post("{:U('Admin/WxUsers/synchroWx')}",'',function(data,textStatus){
					var json = WST.toJson(data);
					if(json.status=='1'){
						userTotal = json.data;
						Plugins.setWaitTipsMsg({content:json.msg,timeout:1000,callback:function(){
						   wxLoad();
						}});
					}else{
						Plugins.closeWindow();
						Plugins.Tips({title:'信息提示',icon:'error',content:json.msg,timeout:1000});
					}
				});
	       }});
   }
   function wxLoad(){
   		id = userTotal[num]['openId'];
   		$.post("{:U('Admin/WxUsers/wxLoad')}",{id:id},function(data,textStatus){
           			  var json = WST.toJson(data);
           			  if(json.status=='1'){
           				    if(num < userTotal.length-1){
           				    	num++
           				    	var msg = "当前正在同步第"+num+"个用户,进度"+num+"/"+userTotal.length;
           				    	Plugins.waitTips({title:'信息提示',content:msg});
        						wxLoad();
           				        return;
           				    }else{
               			    	num=0;
               					Plugins.setWaitTipsMsg({content:'同步完成',timeout:1000,callback:function(){
               						location.reload();
               					}});
           				    }
           			  }else{
  							Plugins.Tips({title:'信息提示',icon:'error',content:json.msg,timeout:1000});
           			  }
           		});
   }
   </script>
   <body class='wst-page'>
    <form method='post' action='{:U("Admin/WxUsers/index")}'>
       <div class='wst-tbar'>
      用户名称：<input type='text' id='userName' name='userName' class='form-control wst-ipt-15' value='{$userName}'/>
       </select>  
  	   <button type="submit" class="btn btn-primary glyphicon glyphicon-search">查询</button>
  	   <php>if(in_array('wyhgl_04',$WST_STAFF['grant'])){</php>
       <a class="btn btn-success glyphicon glyphicon-plus"  href="javascript:void(0);" style='float:right' onclick="javascript:wxSynchro()">与微信用户管理同步</a>
       <php>}</php>
       </div>
       </form>
       <div class="wst-body">
        <table class="table table-hover table-striped table-bordered wst-list">
           <thead>
             <tr>
               <th width='30'>&nbsp;</th>
               <th width='50'>用户头像</th>
               <th width='80'>用户名称</th>
               <th width='60'>性别</th>
               <th width='100'>用户所在地</th> 
               <th width='160'>openId</th>
               <th width='100'>用户关注时间</th>
               <th width='100'>用户备注</th>
             </tr>
           </thead>
           <tbody>
            <volist name="Page['root']" id="vo" key='i'>
             <tr>
               <td>{$i}</td>
               <td><img style="width: 60px;" src="{$vo['userPhoto']}" /></td>
               <td>{$vo['userName']}&nbsp;</td>
               <td>
               <php>if($vo['userSex']==0){</php>保密
               <php>}else if($vo['userSex']==1){</php>男
               <php>}else if($vo['userSex']==2){</php>女
               <php>}</php>
               </td>
               <td>{$vo['userAreas']}&nbsp;</td>
               <td>{$vo['openId']}&nbsp;</td>
               <td>{$vo['subscribeTime']}&nbsp;</td>
               <td><input type='text' value='{$vo['userRemark']}' onchange='javascript:editName(this)' dataId="{$vo.userId}" class='form-control'/></td>
             </tr>
             </volist>
             <tr>
                <td colspan='11' align='center'>{$Page['pager']}</td>
             </tr>
           </tbody>
        </table>
       </div>
   </body>
</html>